'use strict'

$(function () {
    getProductByKeyword();
})

function getProductByKeyword(keyword) {
    let tmp = keyword || '';

    getDataByKeyword(tmp).then((res) => {
        replay(res);
    })
}

function replay(data) {
    let tb = $('#tb');
    let tbData = $('.tbData');
    tbData.remove();
    let h;

    data.forEach(item => {
        h = `
            <tr class="tbData">
            <td>${item.id}</td>
            <td>${item.title}</td>
            <td>${item.digest}</td>
            <td>${item.content}</td>
            <td>${item.variety}</td>
            <td>${item.author}</td>
            <td>${item.createdAt}</td>
            <td>
                <input type="button" value="编辑" onclick="edit(${item.id})">
                <input type="button" value="删除" onclick="del(${item.id})">
            </td>
        </tr>
            `
            tb.append(h);
    });
}

